﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace AikeShoopPro.Admin.Controllers
{
    public class BaseController : Controller
    {
        private string _userId;
        private string _userName;

        protected string UserName
        {
            get
            {
                if (_userName == null)
                    _userName = User.FindFirstValue(ClaimTypes.Name);
                return _userName;
            }
        }

        protected int UserId
        {
            get
            {
                if (_userId == null)
                    _userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

                if (!int.TryParse(_userId, out var id))
                    return 0;

                return id;
            }
        }
    }
}
